package com.kmist.xiakexing.utils;

import com.kmist.xiakexing.base.BaseFragment;
import com.kmist.xiakexing.fragments.MainWorldFragment;
import com.kmist.xiakexing.fragments.PacketsFragment;
import com.kmist.xiakexing.fragments.UnderWorldFragment;

import java.util.HashMap;
import java.util.Map;

public class FragmentCreator {

    private static Map<Integer, BaseFragment> sCache = new HashMap<>();

    public static BaseFragment getFragment(int index){
        BaseFragment baseFragment = sCache.get(index);
        if (baseFragment != null) {
            return baseFragment;
        }
        switch (index){
            case Constants.INDEX_MAINWORLD:{
                baseFragment = new MainWorldFragment();
            }break;
            case Constants.INDEX_UNDERWORLD:{
                baseFragment = new UnderWorldFragment();
            } break;
            case Constants.INDEX_PACKETS:{
                baseFragment = new PacketsFragment();
            }break;
        }

        sCache.put(index, baseFragment);
        return baseFragment;
    }
}
